package javaproject;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import sun.audio.AudioPlayer;
import sun.audio.AudioStream;

public class SoundEX{
    static final int BGM = 0;
    static final int HIT = 1;
    static final int EXPLODE = 2;
    static final int OPTION = 3;

    static final String bgm = "./sound/BGM.wav";
    static final String hit = "./sound/hit.wav";
    static final String explode = "./sound/explode.wav";
    static final String option = "./sound/option.wav";

    public static AudioStream play(int filename)
    {
	try {
	    String file = null;
	    switch(filename)
	    {
		case BGM:
		    file = bgm;
		    break;
		case HIT:
		    file = hit;
		    break;
		case EXPLODE:
		    file = explode;
		    break;
		case OPTION:
		    file = option;
		    break;
	    }
	    AudioStream target = new AudioStream(new FileInputStream(file));
	    AudioPlayer.player.start(target);

	    return target;

	} catch (IOException ex) {
	    Logger.getLogger(SoundEX.class.getName()).log(Level.SEVERE, null, ex);
	}
	return null;
    }
    public static void stop(AudioStream target)
    {
	if(target != null)
	    AudioPlayer.player.stop(target);
    }
}